Hệ thống quản lý thanh toán POS nhà hàng

1 Imports System.Data.OleDb
2 Public Class frmNotesMaster
3   
4     Sub Reset()
5         txtNotes.Text =
""
6         txtNotes.Focus()
7         btnSave.Enabled = True
8         btnUpdate.Enabled = False
9         btnDelete.Enabled = False
10     End Sub
11     Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
12         Me.Close()
13     End Sub
14
15     Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
16         If Len(Trim(txtNotes.Text)) =
0 Then
17             MessageBox.Show(
"Please enter notes", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
18             txtNotes.Focus()
19             Exit Sub
20         End If
21         Try
22             con = New OleDbConnection(cs)
23             con.Open()
24             Dim ct As String =
"select Notes from NotesMaster where Notes=@d1"
25             cmd = New OleDbCommand(ct)
26             cmd.Connection = con
27             cmd.Parameters.AddWithValue(
"@d1", txtNotes.Text)
28             rdr = cmd.ExecuteReader()
29
30             If rdr.Read() Then
31                 MessageBox.Show(
"Notes Already Exists", "Error", MessageBoxButtons.OK, MessageBoxIcon.[Error])
32                 txtNotes.Text =
""
33                 txtNotes.Focus()
34                 If (rdr IsNot Nothing) Then
35                     rdr.Close()
36                 End If
37                 Return
38             End If
39
40             con = New OleDbConnection(cs)
41             con.Open()
42
43             Dim cb As String =
"insert into NotesMaster(Notes) VALUES (@d1)"
44             cmd = New OleDbCommand(cb)
45             cmd.Connection = con
46             cmd.Parameters.AddWithValue(
"@d1", txtNotes.Text)
47             cmd.ExecuteReader()
48             con.Close()
49             Dim st As String =
"added the new Notes '" & txtNotes.Text & "'"
50             LogFunc(lblUser.Text, st)
51             MessageBox.Show(
"Successfully saved", "Record", MessageBoxButtons.OK, MessageBoxIcon.Information)
52             btnSave.Enabled = False
53             Getdata()
54             Reset()
55         Catch ex As Exception
56             MessageBox.Show(ex.Message,
"Error", MessageBoxButtons.OK, MessageBoxIcon.[Error])
57         End Try
58     End Sub
59
60     Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
61         Try
62             If MessageBox.Show(
"Do you really want to delete this record?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) = Windows.Forms.DialogResult.Yes Then
63                 DeleteRecord()
64             End If
65         Catch ex As Exception
66             MessageBox.Show(ex.Message,
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
67         End Try
68     End Sub
69     Private Sub DeleteRecord()
70
71         Try
72             Dim RowsAffected As Integer =
0
73             con = New OleDbConnection(cs)
74             con.Open()
75             Dim cq As String =
"delete from NotesMaster where ID=" & txtID.Text & ""
76             cmd = New OleDbCommand(cq)
77             cmd.Connection = con
78             RowsAffected = cmd.ExecuteNonQuery()
79             If RowsAffected >
0 Then
80                 Dim st As String =
"deleted the Notes '" & txtNotes.Text & "'"
81                 LogFunc(lblUser.Text, st)
82                 MessageBox.Show(
"Successfully deleted", "Record", MessageBoxButtons.OK, MessageBoxIcon.Information)
83                 Getdata()
84                 Reset()
85             Else
86                 MessageBox.Show(
"No Record found", "Sorry", MessageBoxButtons.OK, MessageBoxIcon.Information)
87                 Reset()
88             End If
89             If con.State = ConnectionState.Open Then
90                 con.Close()
91
92             End If
93         Catch ex As Exception
94             MessageBox.Show(ex.Message,
"Error", MessageBoxButtons.OK, MessageBoxIcon.[Error])
95         End Try
96     End Sub
97
98     Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
99         Try
100             If Len(Trim(txtNotes.Text)) =
0 Then
101                 MessageBox.Show(
"Please enter Notes", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
102                 txtNotes.Focus()
103                 Exit Sub
104             End If
105             con = New OleDbConnection(cs)
106             con.Open()
107             Dim cb As String =
"update NotesMaster set Notes=@d1 where ID=" & txtID.Text & ""
108             cmd = New OleDbCommand(cb)
109             cmd.Connection = con
110             cmd.Parameters.AddWithValue(
"@d1", txtNotes.Text)
111             cmd.ExecuteReader()
112             con.Close()
113             Dim st As String =
"updated the Notes '" & txtNotes.Text & "' details"
114             LogFunc(lblUser.Text, st)
115             MessageBox.Show(
"Successfully updated", "Record", MessageBoxButtons.OK, MessageBoxIcon.Information)
116             btnUpdate.Enabled = False
117             Getdata()
118         Catch ex As Exception
119             MessageBox.Show(ex.Message,
"Error", MessageBoxButtons.OK, MessageBoxIcon.[Error])
120         End Try
121     End Sub
122     Public Sub Getdata()
123         Try
124             con = New OleDbConnection(cs)
125             con.Open()
126             cmd = New OleDbCommand(
"SELECT ID,RTRIM(Notes) from NotesMaster order by Notes", con)
127             rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
128             dgw.Rows.Clear()
129             While (rdr.Read() = True)
130                 dgw.Rows.Add(rdr(
0), rdr(1))
131             End While
132             con.Close()
133         Catch ex As Exception
134             MessageBox.Show(ex.Message,
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
135         End Try
136     End Sub
137     Private Sub btnNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNew.Click
138         Reset()
139     End Sub
140
141
142     Private Sub dgw_RowPostPaint(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewRowPostPaintEventArgs) Handles dgw.RowPostPaint
143         Dim strRowNumber As String = (e.RowIndex +
1).ToString()
144         Dim size As SizeF = e.Graphics.MeasureString(strRowNumber, Me.Font)
145         If dgw.RowHeadersWidth < Convert.ToInt32((size.Width +
20)) Then
146             dgw.RowHeadersWidth = Convert.ToInt32((size.Width +
20))
147         End If
148         Dim b As Brush = SystemBrushes.ControlText
149         e.Graphics.DrawString(strRowNumber, Me.Font, b, e.RowBounds.Location.X +
15, e.RowBounds.Location.Y + ((e.RowBounds.Height - size.Height) / 2))
150
151     End Sub
152
153     Private Sub frmNotesMaster_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
154         Getdata()
155     End Sub
156
157     Private Sub dgw_MouseClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles dgw.MouseClick
158         Try
159             If dgw.Rows.Count >
0 Then
160                 Dim dr As DataGridViewRow = dgw.SelectedRows(
0)
161                 txtNotes.Text = dr.Cells(
1).Value.ToString()
162                 txtID.Text = dr.Cells(
0).Value.ToString()
163                 btnUpdate.Enabled = True
164                 btnDelete.Enabled = True
165                 btnSave.Enabled = False
166             End If
167         Catch ex As Exception
168             MessageBox.Show(ex.Message,
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
169         End Try
170     End Sub
171 End Class


Gõ tìm kiếm nhanh...